package com.free.api;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.free.annotation.IgnoreAuth;
import com.free.dao.Assert;
import com.free.service.TokenService;
import com.free.service.UserService;
import com.free.utils.R;

/**
 * 
* @ClassName: ApiLoginController 
* @Description: TODO(API登录授权) 
* @author wujie
* @email 602991693@qq.com 
* @date 2017年8月31日 上午9:38:56 
*
 */
@RestController
@RequestMapping("/api")
public class ApiLoginController {
	@Autowired
	private UserService userService;
	@Autowired
	private TokenService tokenService;
	/**
	 * 
	* @Title: login 
	* @author: wujie
	* @email: 602991693@qq.com
	* @Description: TODO(登录) 
	* @param @param mobile
	* @param @param password
	* @param @return    设定文件 
	* @return R    返回类型 
	* @throws
	 */
	@IgnoreAuth
	@PostMapping("login")
	public R login(String mobile,String password){
		Assert.isBlank(mobile, "手机号不能为空");
		Assert.isBlank(password, "密码不能为空");
		//用户登录
		long userId = userService.login(mobile, password);
		//生成token
		Map<String ,Object> map = tokenService.createToken(userId);
		return R.ok(map);
	}
}
